home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / MacTCP / MacTCP Developer Tools / HyperCard MacTCP Toolkit 1.0 / Source Code ƒ / TCPUtil.inc < prev    next >
Encoding:
Text File  |  1994-11-21  |  4.3 KB  |  163 lines  |  [TEXT/MPS ]

  1. {        Miscellaneous routines used with the TCP XCMDs.
  2.  
  3.     This file in included in the other TCP XCMD source code files -- i.e., it is not compiled and
  4.     linked separately.
  5.  
  6.     Copyright © 1988 Apple Computer, Inc.
  7.  
  8.     Initial coding 12/88 by Harry Chesley.
  9. }
  10.  
  11. const
  12.  
  13. TCPBUFFERSIZE = 4096;        { Amount of space to allocate for each TCP connection (use the minimum to avoid heap fragging. }
  14. INCOMINGBUFSIZE = 1024;    { Incoming buffer size (used by XCMDs for buffering). }
  15. MAGICNUMBER = 'TCPM';        { Unique value used to trap illegal connection IDs. }
  16.  
  17. { csCodes for the TCP driver: }
  18. TCPcsCreate = 30;
  19. TCPcsPassiveOpen = 31;
  20. TCPcsActiveOpen = 32;
  21. TCPcsActOpenWithData = 33;
  22. TCPcsSend = 34;
  23. TCPcsNoCopyRcv = 35;
  24. TCPcsRcvBfrReturn = 36;
  25. TCPcsRcv = 37;
  26. TCPcsClose = 38;
  27. TCPcsAbort = 39;
  28. TCPcsStatus = 40;
  29. TCPcsExtendedStat = 41;
  30. TCPcsRelease = 42;
  31. TCPcsGlobalInfo = 43;
  32.  
  33. type
  34.  
  35. { TCP control block. Note: I'm using a really kludgy, reference by offset approach because the TCP package
  36.     doesn't include Pascal definitions, only C. Eventually I hope they'll do Pascal and this can be converted to
  37.     that approach. In the meantime, I don't want to reinvent wheels, etc. }
  38.  
  39. TCPControlBlk =
  40.     record
  41.         qLink: QElemPtr;
  42.         qType: INTEGER;
  43.         ioTrap: INTEGER;
  44.         ioCmdAddr: Ptr;
  45.         ioCompletion: ProcPtr; {completion routine, or NIL if none}
  46.         ioResult: OSErr; {result code}
  47.         ioNamePtr: StringPtr; {ptr to pathname}
  48.         ioVRefNum: INTEGER; {volume refnum}
  49.         ioCRefNum: INTEGER; {device refnum}
  50.         csCode: INTEGER; {control code}
  51.         ioStreamPointer: longInt; {stream pointer}
  52.         ioParms: array [32..150] of SignedByte;
  53.     end;
  54.  
  55. { TCP connection description: }
  56. TCPConnectionType =
  57.     record
  58.         magic: packed array [1..4] of char;    { A magic number to try and avoid problems with released connection IDs. }
  59.         asyncControlBlock: TCPControlBlk;    { An IO control block for async open calls. }
  60.         incomingPtr: Ptr;                                { Pointer into inBuf of next byte to read. }
  61.         incomingSize: longInt;                        { Number of bytes left in inBuf. }
  62.         buffer: array [1..TCPBUFFERSIZE] of SignedByte;        { Connection buffer. }
  63.         inBuf: array [1..INCOMINGBUFSIZE] of SignedByte;    {Input buffer. }
  64.     end;
  65.  
  66. TCPConnectionPtr = ^TCPConnectionType;
  67.  
  68. var
  69.  
  70. Connection: TCPConnectionPtr;
  71. SyncControlBlock: TCPControlBlk;
  72.  
  73. procedure GetStrParm(n: integer; var str: str255);
  74.     { Get the nth parameter into str. }
  75.  
  76.     begin
  77.         ZeroToPas(paramPtr,paramPtr^.params[n]^,str);
  78.     end;
  79.  
  80. function GetLongParm(n: integer): longInt;
  81.     { Return the nth parameter string, interpreted as a long integer. }
  82.  
  83.     var str: str255;
  84.  
  85.     begin
  86.         ZeroToPas(paramPtr,paramPtr^.params[n]^,str);
  87.         GetLongParm := StrToNum(paramPtr,str);
  88.     end;
  89.  
  90. procedure SetUpConnectionID;
  91.     { Get the first parameter, interpret it as a pointer, and store it in the Connection variable. }
  92.  
  93.     var portIndex: SPortSel;
  94.  
  95.     begin
  96.         Connection := TCPConnectionPtr(GetLongParm(1));
  97.         if Connection^.magic <> MAGICNUMBER then Fail('§§§ invalid connection ID §§§');
  98.         SyncControlBlock := Connection^.asyncControlBlock;
  99.     end;
  100.  
  101. procedure PutControlByteAtOffset(b: SignedByte; o: longInt);
  102.     { Put the specified byte at the offset given within the control block.}
  103.  
  104.     begin
  105.         SyncControlBlock.ioParms[o] := b;
  106.     end;
  107.  
  108. procedure PutControlWordAtOffset(w: integer; o: longInt);
  109.     { Put the specified word at the offset given within the control block.}
  110.  
  111.     var wPtr: ^integer;
  112.  
  113.     begin
  114.         wPtr := @SyncControlBlock.ioParms[o];
  115.         wPtr^ := w;
  116.     end;
  117.  
  118. procedure PutControlLongAtOffset(l: longInt; o: longInt);
  119.     { Put the specified long at the offset given within the control block.}
  120.  
  121.     var lPtr: ^longInt;
  122.  
  123.     begin
  124.         lPtr := @SyncControlBlock.ioParms[o];
  125.         lPtr^ := l;
  126.     end;
  127.  
  128. function ControlByteAtOffset(o: longInt): SignedByte;
  129.     { Return the byte at the offset given within the control block.}
  130.  
  131.     begin
  132.         ControlByteAtOffset := SyncControlBlock.ioParms[o];
  133.     end;
  134.  
  135. function ControlWordAtOffset(o: longInt): integer;
  136.     { Return the word at the offset given within the control block.}
  137.  
  138.     var wPtr: ^integer;
  139.  
  140.     begin
  141.         wPtr := @SyncControlBlock.ioParms[o];
  142.         ControlWordAtOffset := wPtr^;
  143.     end;
  144.  
  145. function ControlLongAtOffset(o: longInt): longInt;
  146.     { Return the long at the offset given within the control block.}
  147.  
  148.     var lPtr: ^longInt;
  149.  
  150.     begin
  151.         lPtr := @SyncControlBlock.ioParms[o];
  152.         ControlLongAtOffset := lPtr^;
  153.     end;
  154.  
  155. procedure ZeroIOParms;
  156.     { Zero out the control block, except for the IORefNum. }
  157.  
  158.     var i: integer;
  159.  
  160.     begin
  161.         for i := 32 to 150 do PutControlByteAtOffset(0,i);
  162.     end;
  163.